<template>
	<view class="container">
		<view class="nav-bar">
			<view class="nav-item" :class="{ active: selected === 'messages' }"
				:style="{ transform: selected === 'messages' ? 'translateY(4px)' : 'translateY(0)' }"
				@click="select('messages')">
				<image class="nav-icon" :src="getIconPath('messages', selected === 'messages')" mode="aspectFit">
				</image>
				<text class="nav-text">{{ '消息' }}</text>
			</view>
			<view class="nav-item" :class="{ active: selected === 'friends' }"
				:style="{ transform: selected === 'friends' ? 'translateY(4px)' : 'translateY(0)' }"
				@click="select('friends')">
				<image class="nav-icon" :src="getIconPath('friends', selected === 'friends')" mode="aspectFit"></image>
				<text class="nav-text">{{ '好友' }}</text>
			</view>
		</view>
		<view class="content">
			<!-- 内容区域 -->
			<TUIConversation v-if="selected === 'messages'"></TUIConversation>
			<contacInfo v-else></contacInfo>
		</view>
	</view>
</template>

<script setup lang="ts">
	import { ref } from 'vue';
	import TUIConversation from '../TUIKit/components/TUIConversation/index.vue'
	import contacInfo from '../TUIKit/components/TUIContact/index.vue'
	import { onShow } from '@dcloudio/uni-app'
	const selected = ref('messages');
	const icons = {
		messages: {
			inactive: '/static/icons/messages_inactive.png',
			active: '/static/icons/messages_active.png'
		},
		friends: {
			inactive: '/static/icons/friends_inactive.png',
			active: '/static/icons/friends_active.png'
		}
	};

	const getIconPath = (item : string, isActive : boolean) : string => {
		return isActive ? icons[item].active : icons[item].inactive;
	};

	const select = (item : string) => {
		selected.value = item;
	};
	onShow(() => {
	  getApp().globalData.getUserInfo()
	})
</script>

<style scoped>
	.container {
		display: flex;
		flex-direction: column;
		height: 100vh;
	}

	.nav-bar {
		display: flex;
		justify-content: space-around;
		align-items: center;
		padding: 8px;
		padding-top: var(--status-bar-height);
		background-color: #ffffff;
		/* 使用更淡雅的背景色 */
		border-bottom: 1px solid #e0e0e0;
		/* 使用更淡的边框色 */
		box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
		/* 可选：添加轻微阴影以增加层次感 */
	}

	.nav-item {
		flex: 1;
		display: flex;
		flex-direction: column;
		align-items: center;
		cursor: pointer;
		transition: transform 0.3s ease;
		position: relative;
		z-index: 1;
	}

	.nav-item.active .nav-text {
		color: #6B64D3;
		/* 选中时文本颜色变化 */
		font-weight: bold;
		/* 选中时文本加粗 */
	}

	.nav-icon {
		width: 20px;
		/* 减小图标大小 */
		height: 20px;
		/* 减小图标大小 */
		margin-bottom: 2px;
		/* 减少图标与文本之间的间距 */
	}

	.nav-text {
		font-size: 14px;
		/* 减小文本字体大小 */
		text-align: center;
		/* 可选：使文本居中对齐 */
	}

	.content {
		flex: 1;
		display: flex;
		justify-content: center;
		align-items: center;
	}
</style>